<?php


class TooltipHelper extends AppHelper {
  
  var $helpers = array('Html');
  
  
  function __construct($options = null) {
  
    parent::__construct($options);
    
     
  } ///////////// end constructor /////////////////
  
  /**
   * Creates a 'warning' type tooltip.  CSS-based.  Be sure to also include the tooltip CSS in the page.
   * 
   * @param string $element  The HTML element for which the tooltip should be applied.
   *                         Note that this element will be wrapped with other elements
   *                         to make the tooltip work.
   * @param string $tooltipBody   The main message of the tooltip.
   * @param string $tooltipHeader (Optional) The header of the tooltip.
   * @return string of the entire html needed to output on a page (includes all tooltip classes, etc)
   */
  function warning($elementStr, $tooltipBody, $tooltipHeader = "Warning") {    
    
    // <editor-fold defaultstate="collapsed" desc="original form of the tooltip elements">
    //    // Tooltip anchor wraps the element that it is a tip for 
    //    <a class="tooltip" href="#">
    //
      //    $element
    //      
    //      <span class="custom warning tooltipSpan">
    //        // Tooltip Image 
    //        $htmlOptions = array('alt'=>'Warning', 'height'=>'48', 'width'=>'48');
    //        $this->Html->image('Warning.png', $htmlOptions); 
    //        
    //        // Tooltip heading and body 
    //        <em>$tooltipHeader</em>
    //        $tooltipBody
    //      </span>
    //    </a>// </editor-fold>

    return $this->tooltipCommon($elementStr, $tooltipBody, "warning", "Warning.png", 
                                "Warning", $tooltipHeader);
    
  } ///////////// end warning() //////////////////////
  
  
  /**
   *
   * @param type $elementStr
   * @param type $tooltipBody
   * @param type $tooltipHeader 
   */
  function info($elementStr, $tooltipBody, $tooltipHeader = "Information") {
    
    return $this->tooltipCommon($elementStr, $tooltipBody, "info", 
                                "Info.png",  "Information", $tooltipHeader);
  } //////////////
  
  
  /**
   *
   * @param type $elementStr
   * @param type $tooltipBody
   * @param type $tooltipHeader 
   */
  function critical($elementStr, $tooltipBody, $tooltipHeader = "Critical") {
    
    return $this->tooltipCommon($elementStr, $tooltipBody, "critical", 
                                "Critical.png", "Critical", $tooltipHeader);
  } //////////////
  
  
  /**
   *
   * @param type $elementStr
   * @param type $tooltipBody
   * @param type $tooltipHeader 
   */
  function help($elementStr, $tooltipBody, $tooltipHeader = "Help") {
    
    return $this->tooltipCommon($elementStr, $tooltipBody, "help", 
                                "Help.png", "Help", $tooltipHeader);
  } //////////////
  
  
  /**
   *
   * @param type $elementStr
   * @param type $tooltipBody
   * @param type $tooltipHeader 
   */
  function classic($elementStr, $tooltipBody) {
    
    $tipTypeSpanClass = 'classic';
    
    return "<a class='tooltip' href='#'>\n".
              "$elementStr\n".
              "<span class='custom $tipTypeSpanClass tooltipSpan'>\n".
                "$tooltipBody\n".
              "</span>\n".
           "</a>\n";
  } //////////////
  
  
  /**
   * Returns the HTML content required for the tooltip.  This is a helper for most of the other
   * tooltip methods.
   *
   * @param type $elementStr
   * @param type $tooltipBody
   * @param type $tipTypeSpanClass
   * @param type $imageName
   * @param type $imageAltText
   * @param type $tooltipHeader
   * @return type 
   */
  protected function tooltipCommon($elementStr, $tooltipBody, $tipTypeSpanClass, 
                                   $imageName, $imageAltText, $tooltipHeader = null) {
    
    // first make the <image> element str
    $htmlOptions = array('alt'=>$imageAltText, 'height'=>'48', 'width'=>'48');
    $imgElementStr = $this->Html->image($imageName, $htmlOptions); 
    
    //return "<a class='tooltip' href='#'>\n".
    return "<a class='cssTooltip' href='#'>\n".
              "$elementStr\n".
              "<span class='custom $tipTypeSpanClass tooltipSpan'>\n".
                "$imgElementStr\n".
                "<em>$tooltipHeader</em>\n".
                "$tooltipBody\n".
              "</span>\n".
           "</a>\n";
    
  } /////////////// end tooltipCommon() //////////

} //////////////////////// end class ////////////////////////////////

?>
